﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class MonAnDAO
    {
        public DataTable LoadDS()
        {
            Data a = new Data();
            string sql = "SELECT MaLoaiMon,TenLoaiMon FROM LoaiMon";
            DataTable dt = new DataTable();
            dt = a.ExecuteQuery(sql);

            return dt;
        }
        public DataTable LoadMonTheoMa(int maMon)
        {
            Data a = new Data();
            string sql = "SELECT MaMon,TenMon,MaLoaiMon,Gia FROM bangmonan where MaLoaiMon = " + maMon + " and IsDelete = 0";
            DataTable dt = new DataTable();
            dt = a.ExecuteQuery(sql);

            return dt;
        }

        public DataTable LoadMenu()
        {
            Data a = new Data();
            string sql = "SELECT MaMon,TenMon,MaLoaiMon,Gia FROM bangmonan where IsDelete = 0";
            DataTable dt = new DataTable();
            dt = a.ExecuteQuery(sql);

            return dt;
        }

        public Boolean ThemMon(MonAnDTO maDTO)
        {
            Data a = new Data();
            string sql = "insert into bangmonan(TenMon, MaLoaiMon, Gia, IsDelete) ";
            sql += "values( N'" + maDTO.TenMon + "',";
            sql += " " + maDTO.Loai + " ,";
            sql += " " + maDTO.Gia + ", 0 )";

            return a.ExecuteNonQuery(sql);
        }

        public Boolean KiemTraTrungMon(string tenmon)
        {
            Data a = new Data();
            string sql = "select * from bangmonan where TenMon = N'" + tenmon + "'";
            DataTable dt = a.ExecuteQuery(sql);
            if (dt.Rows.Count > 0)
                return true;

            return false;
        }

        public Boolean CapNhatMonTrung(string tenmon, int Loai, float gia)
        {
            Data a = new Data();
            string sql = "Update bangmonan set IsDelete = 0, MaLoaiMon = " + Loai + ", Gia = " + gia + " where TenMon = N'" + tenmon + "'";
            return a.ExecuteNonQuery(sql);
        }

        public Boolean XoaMon(int maMon)
        {
            Data a = new Data();
            string sql = "Update bangmonan set IsDelete = 1 where MaMon = '" + maMon + "'";

            return a.ExecuteNonQuery(sql);
        }

        public Boolean CapNhat(MonAnDTO maDTO)
        {
            Data a = new Data();
            string sql = "Update bangmonan set TenMon = N'" + maDTO.TenMon + "', MaLoaiMon = " + maDTO.Loai + " , Gia = " + maDTO.Gia + " where MaMon = " + maDTO.MaMon + " ";

            return a.ExecuteNonQuery(sql);
        }
    }
}
